<template>
	<view class="discount page bgf5">
	
		<!-- 帐户充值 -->
		<account-charge ref="accountCharge" ></account-charge>
		
	
	</view>
</template>

<script>
	const statusBar = uni.getSystemInfoSync().statusBarHeight + 10;
	export default {
		data() {
			return {
				statusBar,
			
				list: [],
				selectShop: null,
				keyword: "",
				isSearch: false,
				id: ''
			};
		},

		onLoad(option) {



			if (option.q) {
				let scan_url = decodeURIComponent(option.q);

				console.info("===option==" + scan_url)

				var index = scan_url.lastIndexOf("\/");
				var result = scan_url.substring(index + 1, scan_url.length);
				this.id = result.split("-")[0];
			
			}
			if (option.scene) {
				let scan_url = option.scene;
				var index = scan_url.lastIndexOf("\/");
				var result = scan_url.substring(index + 1, scan_url.length);
				this.id = result.split("-")[0];
			}	


		},

		onShow() {
			this.getDetail();
			
		},
		methods: {

			search(e) {

				this.keyword = e;
				this.getShopList();
				this.isSearch = true;
				console.info("=====search=====" + e);
			},

			getDetail() {
				let param = {
					id: this.id
				};
				let that = this;
				this.$api.getShopDetail(param).then(res => {

					console.info(JSON.stringify(res));
					if (res.code == 1) {
						that.selectShop = res.data;
						that.onSelectShop(res.data);
					} else {

					}
				})
			},

			// 选择店铺
			onSelectShop(item) {
				this.selectShop = item;
				this.isSearch = false;
				this.$refs.accountCharge.getCharge(this.selectShop);
				
			},
			getShopList() {
				let param = {
					keyword: this.keyword,
					orgId: uni.getStorageSync("orgId", 53)
				};
				let that = this;
				this.$api.shopList(param).then(res => {
					console.info(JSON.stringify(res));
					if (res.code == 1) {
						that.list = res.data;
						console.info("=====dddddddd===" + that.id);
						if (that.id == "") {
							that.selectShop = that.list[0];
							
							
						} else {
							that.getDetail();
						}

					} else {

					}
				})
			},
			switchTab(index) {
				this.currentTab = index;
				this.$nextTick(() => {
					if (this.currentTab == 0) {
						this.$refs.accountRecharge.getCharge(this.selectShop);
					} else if (this.currentTab == 1) {
						this.$refs.groupCoupon.getData(this.selectShop);
					} else if (this.currentTab == 2) {
						this.$refs.couponBox.getData(this.selectShop);
					} else if (this.currentTab == 3) {
						this.$refs.integralBox.getData(this.selectShop);

					} else if (this.currentTab == 4) {
						this.$refs.meituanVer.getData(this.selectShop)

					}
				})
			},

		
		}
	}
</script>

<style lang="scss">
	.discount {
		.icon {
			width: 38rpx;
		}

		.down {
			width: 20rpx;
			height: 20rpx;
		}

		.ellipsis1 {
			max-width: 200rpx;
		}

		.active {
			position: relative;

			&::after {
				content: '';
				width: 120rpx;
				height: 8rpx;
				background-color: #576DAB;
				border-radius: 8rpx;
				position: absolute;
				bottom: 0;
				left: calc(50% - 60rpx);
			}
		}
	}
</style>